package ink.ykb.j2CacheDemo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.annotation.JsonView;

import ink.ykb.j2CacheDemo.entity.User;
import ink.ykb.j2CacheDemo.service.UserService;
import ink.ykb.j2CacheDemo.util.CommonResult;
import ink.ykb.j2CacheDemo.util.FilterView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags= {"接口文档"})
@RequestMapping("/")
@Controller
public class MainController {

	@Autowired
	private UserService userService;
	

	
	@ApiOperation(value="登录")
	@GetMapping("/login")
	public String login(){
		return "login";
	}
	@ApiOperation(value="主页")
	@GetMapping("/index")
	public String index(){
		return "index";
	}
	
	
	
	
	@ApiOperation(value="获取用户信息", notes="")
	@PostMapping("/test/user/info")
	@ResponseBody
	@JsonView(FilterView.OutputAutoMark.class)
//	@JsonView(FilterView.OutputPassword.class)
	public CommonResult userInfo(@RequestParam Integer id){
			
			User user = userService.getUser(id);
			return CommonResult.resultSuccess(user, 1);
	}
	
	@ApiOperation(value="更新用户信息", notes="")
	@PostMapping("/test/user/update")
	@ResponseBody
	@JsonView(FilterView.OutputAutoMark.class)
	public CommonResult updateUserInfo(User user){
			
//			userService.updateUserLock(user);
			userService.updateUser(user);
			return CommonResult.resultSuccess("更新成功");
	}
	@ApiOperation(value="添加用户信息", notes="")
	@PostMapping("/test/user/add")
	@ResponseBody
	@JsonView(FilterView.OutputAutoMark.class)
	public CommonResult addUserInfo(User user){
		userService.addUser(user);
		return CommonResult.resultSuccess("新增成功");
	}
	
	
}
